package com.zch.starter.sentinel.springboot.starter.config;

public class SentinelResult<T> {
    private int code;
    private String message;
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
    public static SentinelResult rejectPass(){
        SentinelResult result = new SentinelResult();
        result.setCode(429);
        result.setMessage("请求过于频繁触发限流，请调整访问频率稍后重试");
        return result;
    }
    public static SentinelResult pass() {
        SentinelResult result = new SentinelResult();
        result.setCode(200);
        result.setMessage("通过");
        return result;
    }

    public static <T> SentinelResult<T> pass(T data) {
        SentinelResult result = SentinelResult.pass();
        result.setData(data);
        return result;
    }
}
